
/*
 * (a)  (C) 1990 by Adobe Systems Incorporated. All rights reserved.
 *
 * (b)  If this Sample Code is distributed as part of the Display PostScript
 *	System Software Development Kit from Adobe Systems Incorporated,
 *	then this copy is designated as Development Software and its use is
 *	subject to the terms of the License Agreement attached to such Kit.
 *
 * (c)  If this Sample Code is distributed independently, then the following
 *	terms apply:
 *
 * (d)  This file may be freely copied and redistributed as long as:
 *	1) Parts (a), (d), (e) and (f) continue to be included in the file,
 *	2) If the file has been modified in any way, a notice of such
 *      modification is conspicuously indicated.
 *
 * (e)  PostScript, Display PostScript, and Adobe are registered trademarks of
 *	Adobe Systems Incorporated.
 * 
 * (f) THE INFORMATION BELOW IS FURNISHED AS IS, IS SUBJECT TO
 *	CHANGE WITHOUT NOTICE, AND SHOULD NOT BE CONSTRUED
 *	AS A COMMITMENT BY ADOBE SYSTEMS INCORPORATED.
 *	ADOBE SYSTEMS INCORPORATED ASSUMES NO RESPONSIBILITY
 *	OR LIABILITY FOR ANY ERRORS OR INACCURACIES, MAKES NO
 *	WARRANTY OF ANY KIND (EXPRESS, IMPLIED OR STATUTORY)
 *	WITH RESPECT TO THIS INFORMATION, AND EXPRESSLY
 *	DISCLAIMS ANY AND ALL WARRANTIES OF MERCHANTABILITY, 
 *	FITNESS FOR PARTICULAR PURPOSES AND NONINFRINGEMENT
 *	OF THIRD PARTY RIGHTS.
 */

/*
   filename	: hdshowany.m
   date created	:  9-feb-90
   last updated	: 26-oct-90
   author		: ross a jeynes
   porter		: ken r fromm
   purpose	: showany routine for generic driver.  This is the central text-setting
				routine.  Handles (font changes-temporarily removed), kerning,
				underline, superscript, etc.
*/

#import "hdshowany.h"
#import "DrawingViewWraps.h"

#import <objc/Storage.h>
#import <dpsclient/dpsclient.h>
#import <dpsclient/wraps.h>

static void hd_showstr(int start, int end, ShowStruct *show, float spaceval, float trackval)
{
	if (start == end)
		return;

	/*
	*	Decide wether to use show, ashow, widthshow or awidthshow
	*/
	if (spaceval == 0.0)
	{
		if (trackval == 0.0)
		 	PSWShow((char *)((show->text)+start), (end-start));
		else
			PSWAshow(trackval, 0,  (char *)((show->text)+start), (end-start));
	}
	else
	{
		if (trackval == 0.0)
			PSWWidthshow(spaceval, 0, 32, (char *)((show->text)+start), (end-start));
		else
		 	PSWAwidthshow(spaceval, 0, 32, trackval, 0, (char *)((show->text)+start), (end-start));
	}
}

void ShowAny(ShowStruct *show)
{
	int lastshow=0;			/* last "show" went from this point in show->text[] */

	/* indexes into ShowStruct arrays */

	int textptr			=0;			/* current character in show->text[] */
	int prkernptr		=0;			/* pair kern */
	int absmovptr		=0;			/* absolute moveto array index */
	int spaceadjptr	=0;			/* space adjustment for justification */
	int trackkernptr	=0;			/* track kern */

	float spaceval		=0.0;
	float trackval		=0.0;

	while (textptr < show->textlen)
	{
		if (show->attr[textptr] == SA_NOATTR)
		{
			textptr++;
			continue;
		}

		if (lastshow != textptr)
			hd_showstr(lastshow, textptr, show, spaceval, trackval);

		if (show->attr[textptr] & SA_ABSMOV)
		{
			PSmoveto(show->absmov[absmovptr].x, show->absmov[absmovptr].y);
			absmovptr++;
		}
		if (show->attr[textptr] & SA_PRKERN)
			PSrmoveto(show->prkern[prkernptr++], 0);
		if (show->attr[textptr] & SA_TRACKADJ)
			trackval = (show->trackkernlen ? show->trackkern[trackkernptr++] : 0.0);
		if (show->attr[textptr] & SA_SPACEADJ)
			spaceval = (show->spaceadjlen ? show->spaceadj[spaceadjptr++] : 0.0);

		lastshow = textptr++;  /* mark last show and increment show pointer */
	}

	hd_showstr(lastshow, textptr, show, spaceval, trackval);
}
